// portal.js, May 19th 2005
// James Smith
// portal.js provides the javascript that is needed to use the portal tag libraries javascript features
// examples:
//   Context menu drop down
//   Box Sub Section collapsing

// scipt used to allow collapsible sub sections
function toggleSubSection(domObject) {

    var sibling;
    // if the sibling's node type is 3, it is text() - some browsers treat text() as a node others do not
    // if it is text() we go to the next sibling again to get the non-text() sibling
    if (domObject.parentNode.nextSibling.nodeType == 3) {
        sibling = domObject.parentNode.nextSibling.nextSibling;
    } else {
        sibling = domObject.parentNode.nextSibling;
    }

    // make sure we found a P element
    if (sibling.nodeName == 'DIV') {

        // toggle the display from block to none
        sibling.style.display = (sibling.style.display == 'none') ? 'block' : 'none';

        // toggle the image in the image node
        var imgNode;
        // finding the image node requires the parent's first child's first child
        if (document.all) {
            // for IE
            imgNode = domObject.parentNode.children[0].children[0];
        } else {
            // for non-IE
            imgNode = domObject.parentNode.childNodes[0].childNodes[0];
        }

        // toggle the node from plus.gif to minus.gif
        if (imgNode.src.indexOf('/images/portal/plus.gif') != -1 ) {
            imgNode.src = './images/portal/minus.gif';
        } else {
            imgNode.src = './images/portal/plus.gif';
        }
        return;
    }
}

// generic functions used in content menu drop dwon
function show(domObject) {

    if (document.layers) {
        domObject.visibility = 'show'
    } else if (document.all) {
        domObject.style.visibility = 'visible';
    } else if (document.getElementById) {
        domObject.style.visibility = 'visible';
    }

}

function hide(domObject) {

    if (document.layers) {
        domObject.visibility = 'hide'
    } else if (document.all) {
        domObject.style.visibility = 'hidden';
    } else if (document.getElementById) {
        domObject.style.visibility = 'hidden';
    }

}

function toggle(domObject) {

    if (document.layers) {
        if(domObject.visibility == 'hide') {
            domObject.visibility = 'show';
        } else {
            domObject.visibility = 'hide';
        }
    } else if (document.all) {
        if(domObject.style.visibility == 'hidden') {
            domObject.style.visibility = 'visible';
        } else {
            domObject.style.visibility = 'hidden';
        }
    } else if (document.getElementById) {
        if(domObject.style.visibility == 'hidden') {
            domObject.style.visibility = 'visible';
        } else {
            domObject.style.visibility = 'hidden';
        }
    }

}

function showDropDown(domObject) {

    var children;

    if (document.all) {
        children = domObject.children;
    } else if (document.getElementById) {
        children = domObject.childNodes;
    }

    for (i = 0; i < children.length; i++) {
        if (children[i].nodeName == 'UL') {
            show(children[i]);
        }
    }
}

function hideDropDown(domObject) {

    var children;
    if (document.all) {
        children = domObject.children;
    } else if (document.getElementById) {
        children = domObject.childNodes;
    }

    for (i = 0; i < children.length; i++) {
        if (children[i].nodeName == 'UL') {
            hide(children[i]);
        }
    }

}